/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on 23.Kas.2009, 20:43:32
 */
package edu.iyte.ceng431.hw2.pos.view;

import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.util.Observable;
import java.util.Observer;

import edu.iyte.ceng431.hw2.pos.model.Cashier;
import edu.iyte.ceng431.hw2.pos.model.Register;
import edu.iyte.ceng431.hw2.pos.model.Sale;

/**
 * 
 * @author 
 */
public class MainFrame extends javax.swing.JFrame implements Observer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Sale sale;
	private Register reg;
	private Cashier cas;
	private java.sql.Date now = new java.sql.Date(new java.util.Date()
			.getTime());

	/** Creates new form MainFrame */
	public MainFrame(Register re, Cashier ca) {
		this.reg = re;
		this.reg.addObserver(this);
		this.cas = ca;
		this.sale = reg.getCurrentsale();
		this.sale.addObserver(this);
		initComponents();
		this.setLocationRelativeTo(null);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		mainTabbedPane = new javax.swing.JTabbedPane();
		salesPanel = new javax.swing.JPanel();
		balanceLabel = new javax.swing.JLabel();
		balanceTextField = new javax.swing.JTextField();
		dateLabel = new javax.swing.JLabel();
		dateTextField = new javax.swing.JTextField();
		cashierLabel = new javax.swing.JLabel();
		cashierTextField = new javax.swing.JTextField();
		registerLabel = new javax.swing.JLabel();
		registerTextField = new javax.swing.JTextField();
		productIdLabel = new javax.swing.JLabel();
		quantityLabel = new javax.swing.JLabel();
		productIdTextField = new javax.swing.JTextField();
		quantityTextField = new javax.swing.JTextField();
		productLabel = new javax.swing.JLabel();
		subTotalLabel = new javax.swing.JLabel();
		subtotalTextField = new javax.swing.JTextField();
		productTextField = new javax.swing.JTextField();
		jScrollPane1 = new javax.swing.JScrollPane();
		saleLineItemsList = new javax.swing.JList();
		addButton = new javax.swing.JButton();
		endSaleButton = new javax.swing.JButton();
		totalLabel = new javax.swing.JLabel();
		totalTextField = new javax.swing.JTextField();
		jSeparator1 = new javax.swing.JSeparator();
		taxLabel = new javax.swing.JLabel();
		taxTextField = new javax.swing.JTextField();
		reportsPanel = new javax.swing.JPanel();
		fromDateLabel = new javax.swing.JLabel();
		toDateLabel = new javax.swing.JLabel();
		fromDayComboBox = new javax.swing.JComboBox();
		fromMonthComboBox = new javax.swing.JComboBox();
		fromYearComboBox = new javax.swing.JComboBox();
		toDayComboBox = new javax.swing.JComboBox();
		toMonthComboBox = new javax.swing.JComboBox();
		toYearComboBox = new javax.swing.JComboBox();
		getReportsButton = new javax.swing.JButton();
		returnPanel = new javax.swing.JPanel();
		saleIdLabel = new javax.swing.JLabel();
		saleIdTextField = new javax.swing.JTextField();
		jScrollPane2 = new javax.swing.JScrollPane();
		returnSaleItemList = new javax.swing.JList();
		getSaleItemsButton = new javax.swing.JButton();
		returnQuantityLabel = new javax.swing.JLabel();
		returnQuantityTextField = new javax.swing.JTextField();
		returnButton = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setTitle("POS System by E-GO");

		balanceLabel.setText("Current Register Balance");

		balanceTextField.setEditable(false);
		balanceTextField.setText(String.valueOf(this.reg.getBalance()));

		dateLabel.setText("Date");

		dateTextField.setEditable(false);
		dateTextField.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
		dateTextField.setText(new java.sql.Date(new java.util.Date().getTime())
				.toString());

		cashierLabel.setText("Cashier");

		cashierTextField.setEditable(false);
		cashierTextField
				.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
		cashierTextField.setText(this.cas.getName());

		registerLabel.setText("Register");

		registerTextField.setEditable(false);
		registerTextField
				.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
		registerTextField.setText(String.valueOf(this.reg.getId()));

		productIdLabel.setText("Product ID");

		quantityLabel.setText("Quantity");

		productIdTextField.setText("1");

		quantityTextField.setText("1");

		productLabel.setText("Product Name");

		subTotalLabel.setText("Subtotal");

		subtotalTextField.setEditable(false);
		subtotalTextField
				.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
		subtotalTextField.setText("0");

		productTextField.setEditable(false);

		saleLineItemsList.setCellRenderer(new SaleRenderer());
		jScrollPane1.setViewportView(saleLineItemsList);

		addButton.setText("ADD");

		endSaleButton.setText("END SALE");

		totalLabel.setText("TOTAL");

		totalTextField.setEditable(false);
		totalTextField.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
		totalTextField.setText("0.0");

		taxLabel.setText("TAX");

		taxTextField.setEditable(false);
		taxTextField.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
		taxTextField.setText("0.0");

		javax.swing.GroupLayout salesPanelLayout = new javax.swing.GroupLayout(
				salesPanel);
		salesPanel.setLayout(salesPanelLayout);
		salesPanelLayout
				.setHorizontalGroup(salesPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								salesPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												salesPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																salesPanelLayout
																		.createSequentialGroup()
																		.addComponent(
																				jSeparator1,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				511,
																				Short.MAX_VALUE)
																		.addContainerGap())
														.addComponent(
																jScrollPane1,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																521,
																Short.MAX_VALUE)
														.addGroup(
																salesPanelLayout
																		.createSequentialGroup()
																		.addGroup(
																				salesPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING,
																								salesPanelLayout
																										.createSequentialGroup()
																										.addGroup(
																												salesPanelLayout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.LEADING,
																																false)
																														.addComponent(
																																balanceTextField)
																														.addComponent(
																																balanceLabel,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																Short.MAX_VALUE)
																														.addGroup(
																																salesPanelLayout
																																		.createSequentialGroup()
																																		.addGroup(
																																				salesPanelLayout
																																						.createParallelGroup(
																																								javax.swing.GroupLayout.Alignment.TRAILING,
																																								false)
																																						.addComponent(
																																								productIdTextField,
																																								javax.swing.GroupLayout.Alignment.LEADING)
																																						.addComponent(
																																								productIdLabel,
																																								javax.swing.GroupLayout.Alignment.LEADING,
																																								javax.swing.GroupLayout.DEFAULT_SIZE,
																																								javax.swing.GroupLayout.DEFAULT_SIZE,
																																								Short.MAX_VALUE))
																																		.addPreferredGap(
																																				javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																																				27,
																																				Short.MAX_VALUE)
																																		.addGroup(
																																				salesPanelLayout
																																						.createParallelGroup(
																																								javax.swing.GroupLayout.Alignment.LEADING)
																																						.addComponent(
																																								quantityTextField)
																																						.addComponent(
																																								quantityLabel,
																																								javax.swing.GroupLayout.Alignment.TRAILING))))
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																												69,
																												Short.MAX_VALUE)
																										.addGroup(
																												salesPanelLayout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.TRAILING)
																														.addGroup(
																																salesPanelLayout
																																		.createSequentialGroup()
																																		.addGroup(
																																				salesPanelLayout
																																						.createParallelGroup(
																																								javax.swing.GroupLayout.Alignment.LEADING)
																																						.addGroup(
																																								javax.swing.GroupLayout.Alignment.TRAILING,
																																								salesPanelLayout
																																										.createSequentialGroup()
																																										.addComponent(
																																												productLabel)
																																										.addPreferredGap(
																																												javax.swing.LayoutStyle.ComponentPlacement.RELATED))
																																						.addGroup(
																																								javax.swing.GroupLayout.Alignment.TRAILING,
																																								salesPanelLayout
																																										.createSequentialGroup()
																																										.addGroup(
																																												salesPanelLayout
																																														.createParallelGroup(
																																																javax.swing.GroupLayout.Alignment.TRAILING,
																																																false)
																																														.addComponent(
																																																registerTextField)
																																														.addComponent(
																																																registerLabel,
																																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																																Short.MAX_VALUE))
																																										.addGap(
																																												18,
																																												18,
																																												18)
																																										.addGroup(
																																												salesPanelLayout
																																														.createParallelGroup(
																																																javax.swing.GroupLayout.Alignment.LEADING,
																																																false)
																																														.addComponent(
																																																cashierTextField,
																																																javax.swing.GroupLayout.Alignment.TRAILING,
																																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																																139,
																																																Short.MAX_VALUE)
																																														.addComponent(
																																																cashierLabel,
																																																javax.swing.GroupLayout.Alignment.TRAILING)
																																														.addComponent(
																																																productTextField,
																																																javax.swing.GroupLayout.PREFERRED_SIZE,
																																																139,
																																																javax.swing.GroupLayout.PREFERRED_SIZE))))
																																		.addGap(
																																				18,
																																				18,
																																				18)
																																		.addGroup(
																																				salesPanelLayout
																																						.createParallelGroup(
																																								javax.swing.GroupLayout.Alignment.TRAILING)
																																						.addGroup(
																																								salesPanelLayout
																																										.createParallelGroup(
																																												javax.swing.GroupLayout.Alignment.LEADING)
																																										.addGroup(
																																												salesPanelLayout
																																														.createSequentialGroup()
																																														.addGap(
																																																84,
																																																84,
																																																84)
																																														.addComponent(
																																																dateLabel))
																																										.addGroup(
																																												javax.swing.GroupLayout.Alignment.TRAILING,
																																												salesPanelLayout
																																														.createSequentialGroup()
																																														.addGap(
																																																67,
																																																67,
																																																67)
																																														.addComponent(
																																																subTotalLabel)))
																																						.addComponent(
																																								dateTextField,
																																								javax.swing.GroupLayout.PREFERRED_SIZE,
																																								89,
																																								javax.swing.GroupLayout.PREFERRED_SIZE)))
																														.addComponent(
																																subtotalTextField,
																																javax.swing.GroupLayout.PREFERRED_SIZE,
																																64,
																																javax.swing.GroupLayout.PREFERRED_SIZE)))
																						.addComponent(
																								addButton))
																		.addContainerGap())
														.addGroup(
																javax.swing.GroupLayout.Alignment.TRAILING,
																salesPanelLayout
																		.createSequentialGroup()
																		.addGroup(
																				salesPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addComponent(
																								taxLabel)
																						.addGroup(
																								javax.swing.GroupLayout.Alignment.LEADING,
																								salesPanelLayout
																										.createSequentialGroup()
																										.addComponent(
																												endSaleButton)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																												254,
																												Short.MAX_VALUE)
																										.addComponent(
																												taxTextField,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												63,
																												javax.swing.GroupLayout.PREFERRED_SIZE)))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				salesPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								totalTextField,
																								javax.swing.GroupLayout.Alignment.TRAILING,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								109,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								totalLabel,
																								javax.swing.GroupLayout.Alignment.TRAILING))
																		.addContainerGap()))));
		salesPanelLayout
				.setVerticalGroup(salesPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								salesPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												salesPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																balanceLabel)
														.addComponent(dateLabel)
														.addComponent(
																cashierLabel)
														.addComponent(
																registerLabel))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												salesPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																balanceTextField,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																cashierTextField,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																registerTextField,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																dateTextField,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(7, 7, 7)
										.addComponent(
												jSeparator1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												10,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(1, 1, 1)
										.addGroup(
												salesPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																productIdLabel)
														.addComponent(
																quantityLabel)
														.addComponent(
																subTotalLabel)
														.addComponent(
																productLabel))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addGroup(
												salesPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																productIdTextField,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																quantityTextField,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																subtotalTextField,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																productTextField,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(addButton)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(
												jScrollPane1,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												224, Short.MAX_VALUE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												salesPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																totalLabel)
														.addComponent(taxLabel))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												salesPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																endSaleButton)
														.addComponent(
																totalTextField,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																taxTextField,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addContainerGap()));

		mainTabbedPane.addTab("SALES", salesPanel);

		fromDateLabel.setText("FROM");

		toDateLabel.setText("TO");

		for (int i = 1; i < 32; i++) {
			fromDayComboBox.addItem(i);
		}
		fromDayComboBox.setSelectedItem(Integer.parseInt(now.toString()
				.substring(8, 10)) - 1);

		for (int i = 1; i < 13; i++) {
			fromMonthComboBox.addItem(i);
		}
		fromMonthComboBox.setSelectedItem(Integer.parseInt(now.toString()
				.substring(5, 7)));

		for (int i = Integer.parseInt(now.toString().substring(0, 4)) - 1; i <= Integer
				.parseInt(now.toString().substring(0, 4)); i++) {
			fromYearComboBox.addItem(i);
		}
		fromYearComboBox.setSelectedItem(Integer.parseInt(now.toString()
				.substring(0, 4)));

		for (int i = 1; i < 32; i++) {
			toDayComboBox.addItem(i);
		}

		toDayComboBox.setSelectedItem(Integer.parseInt(now.toString()
				.substring(8, 10)));

		for (int i = 1; i < 13; i++) {
			toMonthComboBox.addItem(i);
		}
		toMonthComboBox.setSelectedItem(Integer.parseInt(now.toString()
				.substring(5, 7)));

		for (int i = Integer.parseInt(now.toString().substring(0, 4)) - 1; i <= Integer
				.parseInt(now.toString().substring(0, 4)); i++) {
			toYearComboBox.addItem(i);
		}
		toYearComboBox.setSelectedItem(Integer.parseInt(now.toString()
				.substring(0, 4)));

		getReportsButton.setText("SHOW REPORTS");

		javax.swing.GroupLayout reportsPanelLayout = new javax.swing.GroupLayout(
				reportsPanel);
		reportsPanel.setLayout(reportsPanelLayout);
		reportsPanelLayout
				.setHorizontalGroup(reportsPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								reportsPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(fromDateLabel)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												fromDayComboBox,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												fromMonthComboBox,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												fromYearComboBox,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(9, 9, 9)
										.addComponent(toDateLabel)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												toDayComboBox,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												toMonthComboBox,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												toYearComboBox,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(18, 18, 18).addComponent(
												getReportsButton)
										.addContainerGap(138, Short.MAX_VALUE)));
		reportsPanelLayout
				.setVerticalGroup(reportsPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								reportsPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												reportsPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																fromDateLabel)
														.addComponent(
																toDateLabel)
														.addComponent(
																fromDayComboBox,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																fromMonthComboBox,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																fromYearComboBox,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																toDayComboBox,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																toMonthComboBox,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																toYearComboBox,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																getReportsButton))
										.addContainerGap(409, Short.MAX_VALUE)));

		mainTabbedPane.addTab("SALES REPORTS", reportsPanel);

		saleIdLabel.setText("SALE ID");

		saleIdTextField.setPreferredSize(new java.awt.Dimension(5, 20));

		returnSaleItemList.setCellRenderer(new SaleRenderer());
		jScrollPane2.setViewportView(returnSaleItemList);

		getSaleItemsButton.setText("GET ITEMS");

		returnQuantityLabel.setText("QUANTITY");

		returnQuantityTextField.setText("1");
		returnQuantityTextField.setPreferredSize(new java.awt.Dimension(5, 20));

		returnButton.setText("RETURN");

		javax.swing.GroupLayout returnPanelLayout = new javax.swing.GroupLayout(
				returnPanel);
		returnPanel.setLayout(returnPanelLayout);
		returnPanelLayout
				.setHorizontalGroup(returnPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								returnPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												returnPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
														.addComponent(
																jScrollPane2,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																511,
																Short.MAX_VALUE)
														.addComponent(
																saleIdLabel,
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																returnPanelLayout
																		.createSequentialGroup()
																		.addComponent(
																				saleIdTextField,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				71,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				getSaleItemsButton))
														.addGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																returnPanelLayout
																		.createSequentialGroup()
																		.addComponent(
																				returnQuantityLabel)
																		.addGap(
																				7,
																				7,
																				7)
																		.addComponent(
																				returnQuantityTextField,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				50,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addGap(
																				18,
																				18,
																				18)
																		.addComponent(
																				returnButton)))
										.addContainerGap()));
		returnPanelLayout
				.setVerticalGroup(returnPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								returnPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(saleIdLabel)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												returnPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																saleIdTextField,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																getSaleItemsButton))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jScrollPane2,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												328, Short.MAX_VALUE)
										.addGap(18, 18, 18)
										.addGroup(
												returnPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																returnQuantityTextField,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																returnQuantityLabel)
														.addComponent(
																returnButton))
										.addGap(14, 14, 14)));

		mainTabbedPane.addTab("RETURN", returnPanel);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup().addContainerGap().addComponent(
						mainTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE,
						536, Short.MAX_VALUE).addContainerGap()));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup().addContainerGap().addComponent(
						mainTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE,
						471, Short.MAX_VALUE).addContainerGap()));

		pack();
	}// </editor-fold>//GEN-END:initComponents

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton addButton;
	private javax.swing.JLabel balanceLabel;
	private javax.swing.JTextField balanceTextField;
	private javax.swing.JLabel cashierLabel;
	private javax.swing.JTextField cashierTextField;
	private javax.swing.JLabel dateLabel;
	private javax.swing.JTextField dateTextField;
	private javax.swing.JButton endSaleButton;
	private javax.swing.JLabel fromDateLabel;
	private javax.swing.JComboBox fromDayComboBox;
	private javax.swing.JComboBox fromMonthComboBox;
	private javax.swing.JComboBox fromYearComboBox;
	private javax.swing.JButton getReportsButton;
	private javax.swing.JButton getSaleItemsButton;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JScrollPane jScrollPane2;
	private javax.swing.JSeparator jSeparator1;
	private javax.swing.JTabbedPane mainTabbedPane;
	private javax.swing.JLabel productIdLabel;
	private javax.swing.JTextField productIdTextField;
	private javax.swing.JLabel productLabel;
	private javax.swing.JTextField productTextField;
	private javax.swing.JLabel quantityLabel;
	private javax.swing.JTextField quantityTextField;
	private javax.swing.JLabel registerLabel;
	private javax.swing.JTextField registerTextField;
	private javax.swing.JPanel reportsPanel;
	private javax.swing.JButton returnButton;
	private javax.swing.JPanel returnPanel;
	private javax.swing.JLabel returnQuantityLabel;
	private javax.swing.JTextField returnQuantityTextField;
	private javax.swing.JList returnSaleItemList;
	private javax.swing.JLabel saleIdLabel;
	private javax.swing.JTextField saleIdTextField;
	private javax.swing.JList saleLineItemsList;
	private javax.swing.JPanel salesPanel;
	private javax.swing.JLabel subTotalLabel;
	private javax.swing.JTextField subtotalTextField;
	private javax.swing.JLabel taxLabel;
	private javax.swing.JTextField taxTextField;
	private javax.swing.JLabel toDateLabel;
	private javax.swing.JComboBox toDayComboBox;
	private javax.swing.JComboBox toMonthComboBox;
	private javax.swing.JComboBox toYearComboBox;
	private javax.swing.JLabel totalLabel;
	private javax.swing.JTextField totalTextField;

	// End of variables declaration//GEN-END:variables

	public void update(Observable o, Object arg) {
		int qtty = 0;
		double up = 0;
		if (o instanceof Register)
		{
			//this.saleLineItemsList.removeAll();
			this.sale = reg.getCurrentsale();
			this.sale.addObserver(this);
			this.productTextField.setText("");
		}
		else if(o instanceof Sale){
			qtty = this.sale.getSaleLineItems().get(sale.getSaleLineItems().size() - 1).getQuantity();
			up = this.sale.getSaleLineItems().get(sale.getSaleLineItems().size() - 1).getUnitPrice();
			this.productTextField.setText(this.sale.getSaleLineItems().get(sale.getSaleLineItems().size() - 1).getProduct().getName());
		}
        DecimalFormat df = new DecimalFormat("#.##");
        
        this.subtotalTextField.setText(String.valueOf(up * qtty));
        this.saleLineItemsList.setModel(new SaleListModel(this.sale.getSaleLineItems()));
        this.totalTextField.setText(String.valueOf(this.sale.calculateTotal()));
        double tax = (Double.parseDouble(this.totalTextField.getText())) -
                ((Double.parseDouble(this.totalTextField.getText()))) / 1.08;
        this.taxTextField.setText(String.valueOf(df.format(tax)));
        this.balanceTextField.setText(String.valueOf(this.reg.getBalance()));

    }
	
	public Register getReg() {
		return reg;
	}

	public void setReg(Register reg) {
		this.reg = reg;
	}
	
	public String getFromDate() {
		return (this.fromYearComboBox.getSelectedItem() + "-"
				+ this.fromMonthComboBox.getSelectedItem() + "-" + this.fromDayComboBox
				.getSelectedItem());
	}

	public String getToDate() {
		return (this.toYearComboBox.getSelectedItem() + "-"
				+ this.toMonthComboBox.getSelectedItem() + "-" + this.toDayComboBox
				.getSelectedItem());
	}

	/**
	 * @return the balanceTextField
	 */
	public javax.swing.JTextField getBalanceTextField() {
		return balanceTextField;
	}

	/**
	 * @return the cashierTextField
	 */
	public javax.swing.JTextField getCashierTextField() {
		return cashierTextField;
	}

	/**
	 * @return the dateTextField
	 */
	public javax.swing.JTextField getDateTextField() {
		return dateTextField;
	}

	/**
	 * @return the productIdTextField
	 */
	public javax.swing.JTextField getProductIdTextField() {
		return productIdTextField;
	}

	/**
	 * @return the productTextField
	 */
	public javax.swing.JTextField getProductTextField() {
		return productTextField;
	}

	/**
	 * @return the quantityTextField
	 */
	public javax.swing.JTextField getQuantityTextField() {
		return quantityTextField;
	}

	/**
	 * @return the registerTextField
	 */
	public javax.swing.JTextField getRegisterTextField() {
		return registerTextField;
	}

	/**
	 * @return the subtotalTextField
	 */
	public javax.swing.JTextField getSubtotalTextField() {
		return subtotalTextField;
	}

	/**
	 * @return the totalTextField
	 */
	public javax.swing.JTextField getTotalTextField() {
		return totalTextField;
	}

	/**
	 * @return the returnQuantityTextField
	 */
	public javax.swing.JTextField getReturnQuantityTextField() {
		return returnQuantityTextField;
	}

	/**
	 * @param returnQuantityTextField
	 *            the returnQuantityTextField to set
	 */
	public void setReturnQuantityTextField(
			javax.swing.JTextField returnQuantityTextField) {
		this.returnQuantityTextField = returnQuantityTextField;
	}

	/**
	 * @return the saleIdTextField
	 */
	public javax.swing.JTextField getSaleIdTextField() {
		return saleIdTextField;
	}

	/**
	 * @param saleIdTextField
	 *            the saleIdTextField to set
	 */
	public void setSaleIdTextField(javax.swing.JTextField saleIdTextField) {
		this.saleIdTextField = saleIdTextField;
	}

	public void addLineItemListener(ActionListener add) {
		addButton.addActionListener(add);
	}

	public void addEndSaleListener(ActionListener end) {
		endSaleButton.addActionListener(end);
	}

	public void addReturnListener(ActionListener rtn) {
		returnButton.addActionListener(rtn);
	}

	public void addGetSaleItemsListener(ActionListener gtsale) {
		getSaleItemsButton.addActionListener(gtsale);
	}

	public void addGetReportListener(ActionListener report) {
		getReportsButton.addActionListener(report);
	}

	/**
	 * @return the saleLineItemsList
	 */
	public javax.swing.JList getSaleLineItemsList() {
		return saleLineItemsList;
	}

	/**
	 * @return the returnSaleItemList
	 */
	public javax.swing.JList getReturnSaleItemList() {
		return returnSaleItemList;
	}

	/**
	 * @return the mainTabbedPane
	 */
	public javax.swing.JTabbedPane getMainTabbedPane() {
		return mainTabbedPane;
	}

	/**
	 * @param mainTabbedPane
	 *            the mainTabbedPane to set
	 */
	public void setMainTabbedPane(javax.swing.JTabbedPane mainTabbedPane) {
		this.mainTabbedPane = mainTabbedPane;
	}
}
